#ifndef __HELPER_H__
#define __HELPER_H__

#include "temu.h"
#include "operand.h"

#define FUNC_MASK 0x0000003F
#define RS_MASK 0x03E00000
#define RT_MASK 0x001F0000
#define RD_MASK 0x0000F800
#define SHAMT_MASK 0x000007C0
#define IMM_MASK 0x0000FFFF
#define INDEX_MASK 0x03FFFFFF

#define EXCCODE_MASK 0x0000007C
#define EXL_MASK 0x00000002
#define BD_MASK 0x80000000

#define CODE_MASK 0x03FFFFC0

#define Int 0
#define Mod 1
#define TLBL 2
#define TLBS 3
#define ADEL 4
#define ADES 5
#define IBS 6
#define DBE 7
#define Sys 8
#define Bp 9
#define RI 10
#define CpU 11
#define Ov 12
#define Tr 13
#define WATCH 23
#define MCheck 24

#define OPCODE_SIZE 6
#define FUNC_SIZE 6
#define RS_SIZE 5
#define RT_SIZE 5
#define RD_SIZE 5
#define SHAMT_SIZE 5
#define IMM_SIZE 16
#define INDEX_SIZE 26

#define REG_NAME(index) regfile[index]
#define CP0_NAME(index) cp0file[index]

/* All function defined with 'make_helper' return the length of the operation. */
#define make_helper(name) void name(uint32_t pc)

static inline uint32_t instr_fetch(uint32_t addr, size_t len) {
	return mem_read(addr, len);
}

/* shared by all helper function */
extern Operands ops_decoded;

#define op_src1 (&ops_decoded.src1)
#define op_src2 (&ops_decoded.src2)
#define op_dest (&ops_decoded.dest)

#ifdef DEBUG
#define print_asm(...) Assert(snprintf(assembly, 80, __VA_ARGS__) < 80, "buffer overflow!")
#else
#define print_asm(...)
#endif


#endif
